package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    public boolean isExists(String id) {
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean exist = false;
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(id)) {
                exist = true;
                break;
            }
        }
        return exist;
    }

    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public Teacher[] findAllTeachers() {
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return teachers;
        } else {
            return null;
        }
    }

    public void deleteTeacherById(String delId) {
        teacherDao.deleteTeacherById(delId);
    }

    public void updateTeacher(Teacher teacher) {
        teacherDao.updateTeacher(teacher);
    }
}
